import pandas as pd
import os
import numpy as np

def calculate_correlation():
    flag = 0
    folder = 'src'
    for file in os.listdir(folder):
        if file.endswith('.csv'):
            flag += 1
            if flag == 1:
                f = pd.read_csv(folder + '/' + file)
                m = np.asarray(f.drop(['uid'],axis=1)).transpose()
            else:
                f = pd.read_csv(folder + '/' + file)
                v = np.asarray(f.drop(['uid'],axis=1)).transpose()
                #print v.shape
                m = np.vstack((m,v))
    print m.shape
    R = np.corrcoef(np.asarray(m))
    print R
#calculate_correlation()

def combine_results():
    folder = 'src'
    c = 0
    flag = 0
    for file in os.listdir(folder):
        if file.endswith('.csv'):
            flag += 1
            f = pd.read_csv(folder + '/' +file)
            result_combine_uid = f.uid
            c += np.asarray(f.drop(['uid'],axis=1))
    c = c/flag

    result_combine = pd.DataFrame(columns=['uid','score'])
    result_combine.uid = result_combine_uid
    result_combine.score = c
    result_combine.to_csv('result_combine.csv',index=None,encoding='utf-8')
combine_results()